home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / mipseb_dblfixup.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  102 lines

  1. ; $Id: mipseb_dblfixup.pro,v 1.3 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; NAME:
  7. ;    MIPSEB_DBLFIXUP
  8. ;
  9. ; PURPOSE:
  10. ;    This procedure exists to fix data improperly written
  11. ;    by IDL due to two separate bugs that have occured in IDL
  12. ;    at different times in its handling of XDR double precision
  13. ;    data on MIPS cpu based machines (SGI, MIPS, and Dec Risc Ultrix)
  14. ;
  15. ;    Bug#1: SGI and MIPS, but not the DecStation).
  16. ;    ---------------------------------------------
  17. ;
  18. ;        IDL 2.4.0 and earlier has a bug that affects users of 
  19. ;        big-endian MIPS cpu based machines. On these systems, all
  20. ;        XDR output of double precision floating point data has its
  21. ;        least and most significant longwords reversed. This presents no
  22. ;        problem as long as such files are only used on these
  23. ;        machines. However, XDR files with double precision
  24. ;        data cannot be moved between these machines and others
  25. ;        without the need to correct the data.
  26. ;
  27. ;        To further complicate matters, IDL versions later than 2.4.0
  28. ;        have this bug corrected, meaning that older double precision
  29. ;        data saved on one of these machines cannot be restored using
  30. ;        a newer version of IDL without using this routine to correct
  31. ;        the data.
  32. ;
  33. ;    Bug#2: Dec Risc Ultrix (DecStation) only
  34. ;    ---------------------------------------------
  35. ;        IDL 4.0 for Dec Ultrix has a bug that causes all
  36. ;        XDR double precision floating point data to have its
  37. ;        least and most significant longwords reversed. This presents
  38. ;        no problem as long as such files are only used on these
  39. ;        machines. However, XDR files with double precision
  40. ;        data cannot be moved between these machines and others
  41. ;        without the need to correct the data.
  42.  
  43. ;
  44. ;      IDL uses XDR for Save/Restore files, and for files opened
  45. ;      with the XDR keyword to OPENR, OPENW, and OPENU.
  46. ;
  47. ;    
  48. ; CATEGORY:
  49. ;    Bug impact mitigation.
  50. ;
  51. ; CALLING SEQUENCE:
  52. ;    MIPSEB_DBLFIXUP, VAR
  53. ;
  54. ; INPUTS:
  55. ;    VAR - An IDL variable of any type (excluding ASSOC variables).
  56. ;        Scalars, arrays, and structures are supported.
  57. ;
  58. ; OUTPUTS:
  59. ;    VAR - Any double precision floating point data contained in
  60. ;          VAR has had its least and most significant longwords
  61. ;          swapped.
  62. ;
  63. ; COMMON BLOCKS:
  64. ;    None.
  65. ;
  66. ; SIDE EFFECTS:
  67. ;    None.
  68. ;
  69. ; MODIFICATION HISTORY:
  70. ;    12, November, 1992, AB
  71. ;    24 July 1995, AB, Updated documentation header to discuss
  72. ;        explain new error.
  73. ;-
  74. ;
  75. ;
  76.  
  77. PRO MIPSEB_DBLFIXUP, VAR
  78.  
  79.   on_error, 2                ; Return to caller if an error occurs
  80.  
  81.   s = size(var)
  82.   type = s(s(0)+1)
  83.   elts = s(s(0) + 2) - 1
  84.  
  85.   if (type eq 5) then begin
  86.     for i = 0, elts do begin
  87.       val = long(var, i*8, 2)        ; Pull out double as two longwords
  88.       ; Swap the two longwords
  89.       tmp = val(0)
  90.       val(0) = val(1)
  91.       val(1) = tmp
  92.       var(i) = double(val, 0, 1)    ; Put it back
  93.     endfor
  94.   endif else if (type eq 8) then begin
  95.     n = n_tags(var) - 1
  96.     for i = 0, n do begin
  97.         newvar = var.(i)        ; Needs to be named var instead of expr
  98.         mipseb_dblfixup, newvar    ; Recursively fix each tag.
  99.         var.(i) = newvar
  100.     endfor
  101.   endif
  102. end